import u from "../utils";
import fetch from "../utils/fetch";
import {PAGE} from "../constants";
import {WeaLocaleProvider} from "ecCom";

const getLabel = WeaLocaleProvider.getLabel;

const _api = u.api(PAGE);
const _fetch = fetch(PAGE);

export default {
  getComponents: () => _api('getComponents'),
  getDesign: appid => _api('design', { data: { appid } }),
  getPageComps: shortkey => _api('getPageComps', { data: { key: shortkey } }),
  getShortKey: appid => _api('getShortKey', { data: { appid }, ignoreError: true }),
  save: (appid, components, style, codeBlock) => _api('config', {
    type: 'post',
    data: { 
      appid, 
      components: JSON.stringify(components),
      style: JSON.stringify(style),
      codeBlock: codeBlock
    },
    msg: getLabel('502231','保存成功') 
  }),
  getSetInfo: appid => _api('setting/info', { data: { appid }, ignoreError: true}),
  getSubmissionAuthority: () => _api('getSubmissionAuthority'),
  getFillinFrequency: () => _api('getFillinFrequency'),
  uploadImg: data => _fetch('uploadFile', {
    method: 'post',
    body: data
  }),
  setUpdate: data => _api('setting/update', {
    type: 'post',
    data: data,
  }),
  wxUpdate: data => _api('wxsetting/update', {
    type: 'post',
    data: data,
  }),
  getWxInfo: appid => _api('wxsetting/info', { data: { appid }, ignoreError: true }),
  getPageRules: appid => _api('rules/info', { data: { appid } }),
  updatePageRules: (appid, rules) => _api('rules/config', { 
    type: 'post',
    data: { appid, rules },
    msg: getLabel('502231', '保存成功')
  }),
  getJoinCube: appid => _api('joinCube/info', { data: { appid } }),
  setJoinCube: (appid, joinSetting) => _api('joinCube/save', {
    type: 'post',
    data: { appid, joinSetting },
    msg: getLabel('502231', '保存成功')
  }),
  isSetCategory: modeId =>_api('joinCube/isSetCategory', { data: { modeId } }),
  //设置文案获取和提交
  getClerkInfo: data => _api('formpageWordingsetting/info',{ data: data }),
  saveClerk: data => _api('formpageWordingsetting/save',{
    type: 'post',
    data: data,
    msg: getLabel('502231', '保存成功')
  }),
  //拓展属性
  setExtendAttr: data => _api('extendAttr/config', { 
    type: 'post', 
    data: data
   }),
  getExtendAttr: appid => _api('extendAttr/info', { data: { appid } })
}